<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.5.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.5.4/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.5.5.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.5.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.5.5.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	var url;
	function searchGrade(){
		$('#dg').datagrid('load',{
			gradeName:$('#search_gradeName').val()
		});
	}
	
	function deleteGrade(){
		var selectRows = $('#dg').datagrid('getSelections');
		if(selectRows.length == 0){
			$.messager.alert("系统提示","请选择要删除的数据！");
		}
		var strIds = [];
		for(i=0;i<selectRows.length;i++){
			strIds.push(selectRows[i].id);
		}
		var ids = strIds.join(",");
		$.messager.confirm("系统提示","您确认要删除这<font color=red>"+selectRows.length+"</font>条数据吗？",function(r){
			if(r){
				$.post("gradedelete",{delIds:ids},function(result){
					if(result.success){
						$.messager.alert("系统提示","您已经成功删除了<font color=red>"+result.delNum+"</font>条数据！");
						$('#dg').datagrid('reload'); 
					}else{
						$.messager.alert("系统提示",'<font color="red">'+selectRows[result.errorIndex].gradeName+'</font>'+result.errorMsg);
					}
				},"json");
			}		
		});
	}
	function openGradeAddDialog(){
		$("#dlg").dialog("open").dialog("setTitle","添加班级信息");
		url="gradesave";
	}
	function closeGradeDialog(){
		$("#dlg").dialog("close");
		resetValue();
	}
	
	function resetValue(){
		$("#gradeName").val("");
		$("#gradeDesc").val("");
	}
	function saveGrade(){
		$("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				if(result.errorMsg){
					$.messager.alert("系统提示",result.errorMsg);
					return;
				}else{
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid('reload'); 
				}
			}
		});
	}
	
	function openGradeModifyDialog(){
		var selectRows = $('#dg').datagrid('getSelections');
		if(selectRows.length != 1){
			$.messager.alert("系统提示","请选择一条要修改的数据！");
			return;
		}
		$("#dlg").dialog("open").dialog("setTitle","修改班级信息");
		var row = selectRows[0];
		$("#fm").form("load",row);
		url="gradesave?id="+row.id;
	}
</script>
<title>班级信息管理</title>
</head>
<body style="margin:5px">
<table class="easyui-datagrid" id="dg" title="班级信息" fitColumns="true" pagination="true" rownumbers="true" fit="true" url="gradelist" toolbar="#tb">
	<thead>
		<tr>
			<th field="cb" checkbox="true"></th>
			<th field="id" width="100">班级序号</th>
			<th field="gradeName" width="150">班级名称</th>
			<th field="gradeDesc" width="250">班级描述</th>
		</tr>
	</thead>
</table>
<div id="tb">
	<div>
		<a href="javascript:openGradeAddDialog()" class="easyui-linkbutton" plain="true" iconCls="icon-add">添加</a>
		<a href="javascript:openGradeModifyDialog()" class="easyui-linkbutton" plain="true" iconCls="icon-edit">修改</a>
		<a href="javascript:deleteGrade()" class="easyui-linkbutton" plain="true" iconCls="icon-remove">删除</a>
	</div>
	<div>&nbsp;班级名称：&nbsp;<input type="text" name="search_gradeName" id="search_gradeName" /><a href="javascript:searchGrade()" class="easyui-linkbutton" plain="true" iconCls="icon-search">搜索</a></div>
	<div id="dlg" class="easyui-dialog" style="width:500px;height:380px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
		<table>
				<tr>
					<td>班级名称：</td>
					<td><input type="text" id="gradeName" name="gradeName" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td valign="top">班级描述：</td>
					<td><textarea rows="8" cols="40" id="gradeDesc" name="gradeDesc"></textarea></td>
				</tr>
		</table>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:saveGrade()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeGradeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
</div>
</body>
</html>